#include <iostream>
#include <io.h>
#include <fcntl.h>
#include <windows.h>
#include <unistd.h>
#include <string>
#include <vector>
#include <fstream>
#include <istream>
#include <ostream>
#include <sys/types.h>
#include <sys/stat.h>
static std::string fileAddress = []() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0), std::cout.tie(0);
	char ffp[1000] = {0};
    GetModuleFileNameA(NULL, ffp, 1000);
	std::string copystrFileNameA = ffp;
    return copystrFileNameA;
}();
std::string solve(int Position) {
	std::fstream fcin("C:\\Users\\lenovo\\Desktop\\Glass_bottles.txt", std::ios::in | std::ios::out | std::ios::binary);
	//std::ios::trunc setNull std::ios::app eof
	if (!fcin.good()) return "Error in the file";
	else fcin.seekg(std::ios::beg);
	std::cout << ">" << fcin.tellg() << fcin.peek() << std::endl;
	int out_x = 0, in_y = 0, sc_w = 0;
	std::string outs;
	char s[1024];
	for (int i = 0; (fcin.get(s, 1024, '\n') || fcin.tellg() != sc_w); ++ i) {
		if (fcin.tellg() < 0) fcin.clear(), fcin.seekg(sc_w + 1, std::ios::beg);
		std::cout << fcin.peek() << " ";
		if (fcin.peek() == -1) break;
		sc_w = fcin.tellg();
		fcin.seekg(sc_w + 1, std::ios::beg);
		std::cout << fcin.tellg() << " " << s << " ";
		if (i == Position - 1) {
			out_x = fcin.tellg();
			fcin.get(s, 1024, '\n');
			sc_w = fcin.tellg();
			fcin.seekg(sc_w + 1, std::ios::beg);
			outs = s;
		}
		if (i >= Position) {
			in_y = fcin.tellg();
			fcin.seekp(out_x, std::ios::beg);
			fcin << s << '\n';
			out_x = fcin.tellp();
			fcin.seekg(in_y, std::ios::beg);
		}
		std::cout << out_x << std::endl;
	}
	fcin.close();
	int fd = open("C:\\Users\\lenovo\\Desktop\\Glass_bottles.txt", 2);
	ftruncate(fd, out_x - 1);
	close(fd);
	return outs;
}
signed main() {
	freopen("C:\\Users\\lenovo\\Desktop\\1.in", "r", stdin);
	int n;
	std::cin >> n;
	std::cout << solve(n) << std::endl;

		return 0;
}